package com.laf.manager.repository;

import com.laf.manager.dto.ParkingRule;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author ygl
 * @create 2018-12-27
 * @DESCRIPTION
 **/
@Repository
@Slf4j
public class ParkingRuleRepository {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    /**
     * 列表查询
     * @return
     */
    public List<ParkingRule> findList(){
        String sql = "SELECT * FROM t_parking_rule";
        List<ParkingRule> list = jdbcTemplate.query(sql,new ParkingRule());
        return list;
    }

    /**
     * 新增
     * @param pointsPerYuan
     * @param mostYuan
     * @return
     */
    public int insert(Integer pointsPerYuan,Integer mostYuan,Integer frozenTime){
        String sql = "INSERT INTO t_parking_rule(points_per_yuan,most_yuan,frozen_time) VALUES (?,?,?)";
        return jdbcTemplate.update(sql, pointsPerYuan,mostYuan,frozenTime);
    }

    public int update(ParkingRule model) {
        String sql = "update t_parking_rule set points_per_yuan=?,most_yuan=?,frozenTime=? where member_id=?";
        return jdbcTemplate.update(sql, new Object[]{model.getPointsPerYuan(),model.getMostYuan(),model.getFrozenTime(),model.getId()});
    }
}

